<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- <button id="btn"></button> -->
    <script>
      function daojishi() {
        var time1 = new Date(); //获取现在的时间
        var time2 = new Date("2021-11-22 8:30:00");
        var time_diff = parseInt((time2.getTime() - time1.getTime()) / 1000); //利用时间戳，两个时间戳相减time2.getTime() - time1.getTime()就是二者时间差
        var day = parseInt(time_diff / (3600 * 24));
        var hours = parseInt(time_diff / 3600) % 24; //求出所有小时 对24取余
        var mins = parseInt(time_diff / 60) % 60; //所有分钟%60  即 多少小时多少分钟
        var secs = time_diff % 60;
        var str = `距离上课时间${day}天${hours}小时${mins}分${secs}秒`;

        document.body.innerHTML = str;
      }

      var timer = setInterval(function () {
        daojishi();
      }, 1000);
    </script>
  </body>
</html>
